<template>
    <div class="map-container">
        <div class="map-header">
            <div class="map-title">陵水县智慧城市运行中心</div>
            <div class="map-header-left">
                <!-- <SelectorGroup @cascaderChange="handleCascaderChange" @dropdownChange="handleDropdownChange" /> -->
            </div>
            <div class="map-header-right">
                <div class="datetime-display">
                    <div class="time">{{ currentTime }}</div>
                    <div style="display: flex;flex-direction: column;align-items: start;">
                        <div class="date">{{ currentDate }}</div>
                        <div class="weekday">{{ currentWeekday }}</div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 左侧可视化组件 -->
        <ScreenLeft />
        <!-- 3D 地图的容器 -->
        <div class="home_map">
            <ArcGISMap />
        </div>
        <!-- 顶部图标导航 -->
        <div class="top-icons">
            <div class="top-icon-item">
                <!-- <img src="../../assets/icon/list1.png" /> -->
                <div class="icon-item-right">
                    <p class="index-text">景区（个）</p>
                    <div class="value">
                        <span class="digit">0</span>
                        <span class="digit">0</span>
                        <span class="digit">0</span>
                        <span class="digit">6</span>
                    </div>
                </div>
            </div>
            <div class="top-icon-item">
                <div class="icon-item-right">
                    <p class="index-text">收入（万元）</p>
                    <div class="value">
                        <span class="digit">0</span>
                        <span class="digit">1</span>
                        <span class="digit">5</span>
                        <span class="digit">9</span>
                    </div>
                </div>
            </div>
            <div class="top-icon-item">
                <div class="icon-item-right">
                    <p class="index-text">人次（万人）</p>
                    <div class="value">
                        <span class="digit">0</span>
                        <span class="digit">0</span>
                        <span class="digit">1</span>
                        <span class="digit">9</span>
                    </div>
                </div>
            </div>
            <div class="top-icon-item">
                <div class="icon-item-right">
                    <p class="index-text">客单价（元）</p>
                    <div class="value">
                        <span class="digit">0</span>
                        <span class="digit">1</span>
                        <span class="digit">2</span>
                        <span class="digit">6</span>
                    </div>
                </div>
            </div>
        </div>
        <!-- 右侧可视化组件 -->
        <ScreenRight />
        <!-- 底部图标导航 -->
        <BottomIconNavigation @iconClick="handleIconClick" />
    </div>

</template>

<script setup>
import { onMounted, ref, onUnmounted, watch } from "vue";
import router from "@/router";

import ScreenLeft from '@/components/DigitalEconomyComponents/ScreenLeft.vue'
import ScreenRight from '@/components/DigitalEconomyComponents/ScreenRight.vue'
import BottomIconNavigation from '@/components/BottomIconNavigation.vue'
import ArcGISMap from '@/components/PublicSafetyComponents/ArcGISMap.vue'

// 时间日期相关的响应式数据
const currentTime = ref('');
const currentDate = ref('');
const currentWeekday = ref('');
let timeInterval = null;


// 更新时间的函数
const updateDateTime = () => {
    const now = new Date();

    // 格式化时间 HH:MM:SS
    currentTime.value = now.toLocaleTimeString('zh-CN', {
        hour12: false,
        hour: '2-digit',
        minute: '2-digit',
        second: '2-digit'
    });

    // 格式化日期 YYYY年MM月DD日
    currentDate.value = now.toLocaleDateString('zh-CN', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit'
    });

    // 格式化星期
    currentWeekday.value = now.toLocaleDateString('zh-CN', {
        weekday: 'long'
    });
};

onMounted(() => {
    // 初始化时间显示
    updateDateTime();
    // 每秒1秒更新一次时间
    timeInterval = setInterval(updateDateTime, 1000);

    // createMainFunc();
});

// 组件销毁时清理定时器
onUnmounted(() => {
    if (timeInterval) {
        clearInterval(timeInterval);
        timeInterval = null;
    }
});

// 级联选择器变化处理
const handleCascaderChange = (value) => {
    console.log('级联选择器选择:', value)
    // 这里可以根据选择的区域更新地图视图
}

// 下拉选择器变化处理
const handleDropdownChange = (value) => {
    console.log('下拉选择器选择:', value)
    // 这里可以根据选择的数据类型更新地图显示
}

// 底部图标点击处理
const handleIconClick = (data) => {
    router.push(data.path)
}

</script>

<style scoped lang="scss">
.map-container {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    .home_map {
        width: 100%;
        height: 100%;

        img {
            width: 100%;
            height: 100%;
        }
    }

    .map-header {
        width: 100%;
        height: 7.41vh; // 80px
        // background-color: black;
        background-image: url('../../assets/img/bigScreenHeader.png');
        background-size: cover;
        background-position: center center;
        background-repeat: no-repeat;
        flex-shrink: 0;
        z-index: 10;
        display: flex;
        align-items: center;
        position: fixed;

        .map-title {
            color: #ffffff;
            font-size: calc(24px + 0.42vw);
            font-weight: bold;
            text-align: center;
            font-family: 'Microsoft YaHei', 'PingFang SC', sans-serif;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            white-space: nowrap;
        }

        .map-header-left {
            position: absolute;
            bottom: 0;
            // left: 20px;
            width: 10.42vw; // 200px
            height: 80%;
            flex-shrink: 0;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
            padding: 0.52vw; // 10px
            box-sizing: border-box;
        }

        .map-header-right {
            position: absolute;
            bottom: 0;
            right: 1.04vw; // 20px
            height: 80%;
            // background-color: red;
            flex-shrink: 0;
            display: flex;
            justify-content: flex-end;
            align-items: flex-end;
            padding: 0.52vw; // 10px
            box-sizing: border-box;

            .datetime-display {
                text-align: right;
                color: #ffffff;
                font-family: 'Microsoft YaHei', 'PingFang SC', sans-serif;
                line-height: 1.2;
                display: flex;
                align-items: center;

                .time {
                    font-size: 1.25vw; // 24px
                    font-weight: bold;
                    margin-bottom: 0.28vh; // 3px
                    text-shadow: 0 0 0.42vw rgba(0, 174, 255, 0.6); // 8px
                    background: linear-gradient(45deg, #ffffff, #09add6);
                    background-size: 400% 400%;
                    -webkit-background-clip: text;
                    -webkit-text-fill-color: transparent;
                    background-clip: text;
                    animation: timeGlow 2s ease-in-out infinite alternate;
                    white-space: nowrap;
                    margin-right: 1.04vw; // 20px
                }

                .date {
                    font-size: 0.73vw; // 14px
                    color: rgba(255, 255, 255, 0.9);
                    text-shadow: 0 0 0.26vw rgba(255, 255, 255, 0.3); // 5px
                    letter-spacing: 0.026vw; // 0.5px
                    white-space: nowrap;
                }

                .weekday {
                    font-size: 0.73vw; // 14px
                    color: rgba(255, 255, 255, 0.8);
                    text-shadow: 0 0 0.26vw rgba(255, 255, 255, 0.2); // 5px
                    letter-spacing: 0.026vw; // 0.5px
                    white-space: nowrap;
                    margin-top: 0.19vh; // 2px
                }
            }
        }


    }

    @keyframes timeGlow {
        0% {
            background-position: 0% 50%;
            filter: brightness(1);
        }

        100% {
            background-position: 100% 50%;
            filter: brightness(1.2);
        }
    }

    /* 顶部图标导航样式 */
    .top-icons {
        position: absolute;
        top: 11.11vh; // 120px
        left: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        align-items: center;
        justify-content: space-around;
        /* 使用space-around实现自适应间距 */
        width: 55%;
        /* 设置容器宽度 */
        // max-width: 800px;
        /* 最大宽度限制 */
        z-index: 100;

        .top-icon-item {
            cursor: pointer;
            transition: all 0.3s ease;
            padding: 0.93vh 0.78vw; // 10px 15px
            border-radius: 2.6vw; // 50px
            display: flex;
            align-items: center;
            user-select: none;
            gap: 0.52vw; // 10px

            img {
                width: 2.6vw; // 50px
                height: 2.6vw; // 50px
                object-fit: contain;
                transition: all 0.3s ease;
            }

            .icon-item-right {
                display: flex;
                flex-direction: column;
                align-items: center;

                .index-text {
                    margin: 0;
                    font-size: calc(12px + 0.1vw);
                    color: #fff;
                    font-weight: bold;
                    text-shadow: 0 0 0.26vw rgba(0, 198, 255, 0.5); // 5px
                }

                .value {
                    font-size: calc(16px + 0.2vw);
                    font-weight: bold;
                    color: #fff;
                    text-shadow: 0 0 8px rgba(0, 174, 255, 0.5);
                    display: flex;
                }

                .digit {
                    display: inline-block;
                    padding: 0.1vh 0.40vw; // 2px 5px
                    margin: 0 0.1vw; // 0 2px
                    background: rgba(255, 255, 255, 0.1);
                    backdrop-filter: blur(5px);
                    -webkit-backdrop-filter: blur(5px);
                    border: 1px solid rgba(255, 255, 255, 0.2);
                    border-radius: 0.21vw; // 4px
                    box-shadow: 0 0.1vh 0.26vw rgba(0, 0, 0, 0.1); // 0 2px 5px
                    color: #fff;
                    text-shadow: 0 0 0.42vw rgba(255, 255, 255, 0.8); // 8px
                }

                .value-text {
                    margin: 0;
                    font-size: calc(16px + 0.21vw);
                    color: #ffffff;
                    font-weight: bold;
                    text-shadow: 0 0 0.26vw rgba(255, 255, 255, 0.5); // 5px
                }
            }

            &:hover {
                transform: scale(1.05);
                background: rgba(0, 174, 255, 0.2);
                box-shadow: 0 0 0.78vw rgba(0, 174, 255, 0.5); // 15px

                img {
                    filter: brightness(1.2);
                }
            }
        }
    }

    /* 地图容器的样式 */
    #map {
        background-image: url('../../assets/img/bigScreen.png');
        background-size: cover;
        background-position: center center;
        background-repeat: no-repeat;
        width: 100%;
        flex: 1;
        position: relative;
        padding: 0;
        margin: 0;
        overflow: hidden;
    }

    /* 弹窗样式 */
    .popup-modal {
        position: absolute;
        width: 15.625vw; // 300px
        height: 18.52vh; // 200px
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(0.16vw); // 3px
        -webkit-backdrop-filter: blur(0.52vw); // 10px
        border: 0.05vw solid rgba(255, 255, 255, 0.2); // 1px
        border-radius: 0.42vw; // 8px
        box-shadow: 0 0.37vh 0.625vw rgba(0, 0, 0, 0.3); // 0 4px 12px
        z-index: 1000;
        transform: translate(-50%, -100%);
        margin-top: -0.93vh; // -10px
        pointer-events: auto;
    }

    .popup-content {
        padding: 0.625vw; // 12px
        color: #fff;
        font-size: 0.625vw; // 12px
        text-align: center;
    }

    #chart-container {
        width: 100%;
        height: 15vh;
    }

    .popup-content h3 {
        margin: 0 0 0.56vh 0; // 6px
        font-size: 0.73vw; // 14px
        font-weight: bold;
        text-shadow: 0.05vw 0.09vh 0.1vw rgba(0, 0, 0, 0.5); // 1px 1px 2px
    }

    .popup-content p {
        margin: 0;
        opacity: 0.9;
        text-shadow: 0.05vw 0.09vh 0.1vw rgba(0, 0, 0, 0.5); // 1px 1px 2px
    }
}
</style>
